//
//  LHXMainViewController.m
//  Etwo
//
//  Created by 林浩翔 on 16/6/16.
//  Copyright © 2016年 林浩翔. All rights reserved.
//

#import "LHXMainViewController.h"
#import "LHXCutImageView.h"
#import "LHXBtnItem.h"
#import "LHXMainBtnItem.h"




@interface LHXMainViewController ()


@property (assign,nonatomic)CGFloat scale;

@property (assign,nonatomic)CGFloat pinchScale;


@end

@implementation LHXMainViewController

#pragma mark --懒加载


- (NSArray *)btnItemArray{
    if (_btnItemArray == nil) {
        NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"MainBtn" ofType:@"plist"];
        NSArray *BtnItemArray = [NSArray arrayWithContentsOfFile:plistPath];
        LHXMainBtnItem *MainItem = [LHXMainBtnItem MainItemWithArray:BtnItemArray];
        NSMutableArray *tempArray = [NSMutableArray array];
        for (NSDictionary *dict in MainItem.ChooseViewBtnItem) { // 遍历字典数组中的每一个字典
            // 将字典 转为 模型
            LHXBtnItem *btnItem = [LHXBtnItem itemWithDict:dict];
            
            [tempArray addObject:btnItem];
        }
        _btnItemArray = tempArray;
        
    }
    return _btnItemArray;
}


#pragma mark --view生命周期

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];

    
    if(self.cutImageView.pan == nil){
        //创建手势
        UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self.cutImageView action:@selector(pan:)];

        
        self.cutImageView.pan = pan;
        //添加手势
        [self.cutImageView addGestureRecognizer:pan];
    }
    
    if (self.cutImageView.pinch == nil) {
        //添加捏合手势
        UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc]initWithTarget:self.cutImageView action:@selector(pinch:)];
        
        pinch.delegate = self.cutImageView;
        
        self.cutImageView.pinch = pinch;
        
        [self.mainView addGestureRecognizer:pinch];
    }
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    
}


#pragma mark --按钮点击事件
- (void)BtnClick:(LHXbutton *)btn{

    [LHXchoose shareChoose].cutImageView = self.cutImageView;
    [LHXchoose shareChoose].chooseImage = self.cutImageView.image;

    if ([btn.btnTextTag isEqualToString:@"返回"]) {
        [[NSNotificationCenter defaultCenter] postNotificationName:@"LHXcomeBackFrist" object:self];
    }else if([btn.btnTextTag isEqualToString:@"重新选图"]){
                [self getPicture];
    }else if([btn.btnTextTag isEqualToString:@"裁剪工具"]){
        if (self.cutImageView.pinch) {
            [self.mainView removeGestureRecognizer:self.cutImageView.pinch];
        }
        [[NSNotificationCenter defaultCenter] postNotificationName:@"LHXCutView" object:self];
                
    }else if([btn.btnTextTag isEqualToString:@"文字工具"]){
        [[NSNotificationCenter defaultCenter] postNotificationName:@"LHXWritingView" object:self];
    }
   
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
